// Copyright Leonid Shlyapnikov 2011
// Distributed under the GNU Lesser General Public License http://www.gnu.org/licenses/lgpl.html
//    author: Leonid Shlyapnikov, created on: Aug 10, 2011

#include <boost/test/test_tools.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/cstdint.hpp>

#include <string>
#include <stdexcept>

#include "../../main/fixparser/Uint32ToStringConverter.h"

void Uint32ToStringConverter_test_toString() {
    using fixparser::Uint32ToStringConverter;

    BOOST_CHECK_EQUAL( &Uint32ToStringConverter::toString(5), &Uint32ToStringConverter::toString(5));
    BOOST_CHECK_NE(    &Uint32ToStringConverter::toString(5), &Uint32ToStringConverter::toString(4));

    BOOST_CHECK_EQUAL("0",      Uint32ToStringConverter::toString(0));
    BOOST_CHECK_EQUAL("1",      Uint32ToStringConverter::toString(1));
    BOOST_CHECK_EQUAL("5",      Uint32ToStringConverter::toString(5));
    BOOST_CHECK_EQUAL("9",      Uint32ToStringConverter::toString(9));
    BOOST_CHECK_EQUAL("100",    Uint32ToStringConverter::toString(100));
    BOOST_CHECK_EQUAL("555",    Uint32ToStringConverter::toString(555));
    BOOST_CHECK_EQUAL("9999",   Uint32ToStringConverter::toString(9999));
    BOOST_CHECK_EQUAL("10000",  Uint32ToStringConverter::toString(10000));
    BOOST_CHECK_EQUAL("65534",  Uint32ToStringConverter::toString(65534));

    const boost::uint32_t max = Uint32ToStringConverter::MAX_VALUE;
    BOOST_MESSAGE("Uint32ToStringConverter::MAX_VALUE: " <<  max);
    BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(max), Uint32ToStringConverter::toString(max));

    BOOST_CHECK_THROW(Uint32ToStringConverter::toString(max + 1), std::invalid_argument);
    BOOST_CHECK_THROW(Uint32ToStringConverter::toString(max + 2), std::invalid_argument);

    BOOST_CHECK_THROW(Uint32ToStringConverter::toString(-1),    std::invalid_argument);
    BOOST_CHECK_THROW(Uint32ToStringConverter::toString(-100),  std::invalid_argument);
}
